﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.OracleClient;
using System.Text;
using ReflectionStudio.Core.Events;
using INTEX.DataBase.Tools;
namespace WPFExcelReport
{

    public class JLTGB33Data : BaseFunction
    {
        
        public JLTGB33Data()
            : base()
        {

        }
        public JLTGB33Data(Dictionary<string, object> DicGlobalPara)
            : base(DicGlobalPara)
        {
        }

        public DataSet GetEKGB(DataRow dwABPOS)
        {
            DataSet Result;
            DataSet Return = new DataSet();
            string TableName = "GB33";
            string FROMDNDATE = dwABPOS["FROMDNDATE"].ToString().Trim();
            string ENDDNDATE = dwABPOS["ENDDNDATE"].ToString().Trim();
            string ARTICLE = dwABPOS["ARTICLE"].ToString().Trim();
            string SUPP = dwABPOS["SUPP"].ToString().Trim();
            try
            {
                orlReadCommand = OracleDB.CreateCommand();
                orlReadCommand.CommandText = "SELECT TO_NUMBER(d.gpliefnr) AS SUPP,TRIM(C.LSNAME2) AS SUPPNAME, "
                    + " d.gpgart AS ARTICLE,G.GSHANDLNR,D.GPEINBRUT*0.01 as INQTY, "
                    + " D.GPPARTIE AS LOT,D.GPSPPART AS SPART, d.GPEINDAT, "
                    + " d.gpfibl130*0.1 as AMM,d.gpfibl140*0.1 as BMM ,d.gpfibl11p*0.01 as CMM, "
                    + " d.GPFIBL12P*0.01 AS DMM,d.GPBFORCE*0.1 AS AVCN,d.GPBFORCECV*0.01 AS DIFCN, "
                    + " d.GPELONG*0.01 AS MINCN,d.GPUCV*0.01 AS CV,d.GPTHINP40 AS THINA, "
                    + " d.GPTHINP50 AS THINB,d.GPTHICKP35 AS THICKA,d.GPTHICKP50 AS THICKB, "
                    + " d.GPNEPS140 AS NEPSA,d.GPNEPS200 AS NEPSB,d.GPHAIR*0.01 AS HAIR, "
                    + " d.GPUINDEX*0.001 AS UINDEX,d.GPTITER*0.0001 AS TITER, "
                    + " d.GPENDBKG*0.01 AS ENDB,d.GPENDBHKM*0.01 AS ENDH, "
                    + " d.GPCOMMENT AS REMARK  "
                    + " FROM GPDAT D,LIEFDAT C,GSDAT G "
                    + " WHERE D.GPMANDANT = C.LSMANDANT AND D.GPLIEFNR = C.LSLIEFNR  "
                    + " AND D.GPMANDANT = G.GSMANDANT AND D.GPGART = G.GSART "
                    + " AND D.GPGVAR = G.GSVAR "
                    + " AND (D.GPEINDAT >='" + FROMDNDATE + "'  AND D.GPEINDAT <='" + ENDDNDATE + "') "
                    + " AND D.GPGART LIKE '%"+ARTICLE+"%' "
                    + " AND (D.GPLIEFNR = '"+SUPP+"' OR '"+SUPP+"' = '00000000') "
                    + " order by GPEINDAT,article "
                    ;

                Result = Connect2Proxy(orlReadCommand);
                if (Result.Tables.Count > 0)
                {
                    Result.Tables[0].TableName = TableName;
                    byte[] b;
                    string value;
                    foreach (DataRow dw in Result.Tables[TableName].Rows)
                    {
                        b = Encoding.GetEncoding("ISO-8859-1").GetBytes(dw["SUPPNAME"].ToString().Trim());
                        value = Encoding.GetEncoding("gb2312").GetString(b);
                        dw["SUPPNAME"] = value;
                        b = Encoding.GetEncoding("ISO-8859-1").GetBytes(dw["GSHANDLNR"].ToString().Trim());
                        value = Encoding.GetEncoding("gb2312").GetString(b);
                        dw["GSHANDLNR"] = value;
                        b = Encoding.GetEncoding("ISO-8859-1").GetBytes(dw["REMARK"].ToString().Trim());
                        value = Encoding.GetEncoding("gb2312").GetString(b);
                        dw["REMARK"] = value;
                        b = Encoding.GetEncoding("ISO-8859-1").GetBytes(dw["SPART"].ToString().Trim());
                        value = Encoding.GetEncoding("gb2312").GetString(b);
                        dw["SPART"] = value;
                    }
                }
                Return.Merge(Result);
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            return Return;
        }       
        public DataSet BuildJLTGB33Data(DataRow dwUI)
        {
            DataSet setReturn = new DataSet();
            DataSet setResult = new DataSet();
            try
            {
                setResult = GetEKGB(dwUI);
                setReturn.Merge(setResult);                
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            return setReturn;
        }
    }
}